using System;
using System.Collections.Generic;
using System.Text;

using System.Management.Automation;

namespace Microsoft.PowerShell.CmdletManagement
{
    [Cmdlet(VerbsCommon.Add, "PsSpecCmdletParameterSetEntry", SupportsShouldProcess = true)]
    public class AddPsSpecCmdletParameterEntryCommand : PsSpecCommandBase
    {
        [ValidateLength(2, 100)]
        [Parameter(Mandatory = true, ValueFromPipelineByPropertyName = true)]
        public string CmdletName
        {
            get { return _cmdletName; }
            set { _cmdletName = value; }
        }
        private string _cmdletName = null;

        [ValidateLength(3, 50)]
        [Parameter(Mandatory = true, ValueFromPipelineByPropertyName = true)]
        public string ProjectName
        {
            get { return _projectName; }
            set { _projectName = value; }
        }
        private string _projectName = null;

        [Parameter(Mandatory = true, ValueFromPipelineByPropertyName = true)]
        [ValidateLength(1, 100)]
        public string ParameterName
        {
            get
            {
                return _name;
            }
            set
            {
                _name = value;
            }
        }
        private string _name = "*";

        [Parameter(ValueFromPipelineByPropertyName = true)]
        public string ParameterSetName
        {
            get
            {
                return _parameterSetName;
            }
            set
            {
                if ((value != null) && (value.Length > 50))
                    throw new ArgumentOutOfRangeException("ParameterSetName");

                _parameterSetName = value;
            }
        }
        private string _parameterSetName = null;

        [Parameter(ValueFromPipelineByPropertyName = true)]
        public bool Mandatory
        {
            get { return mandatory; }
            set { mandatory = value; }
        }
        private bool mandatory = false;

        [Parameter(ValueFromPipelineByPropertyName = true)]
        [AllowNull]
        public int? Position
        {
            get { return _position; }
            set { _position = value; }
        }
        private int? _position;

        [Parameter(ValueFromPipelineByPropertyName = true)]
        public bool ValueFromPipeline
        {
            get { return _valueFromPipeline; }
            set { _valueFromPipeline = value; }
        }
        private bool _valueFromPipeline = false;

        [Parameter(ValueFromPipelineByPropertyName = true)]
        public bool ValueFromPipelineByPropertyName
        {
            get { return _valueFromPipelineByPropertyName; }
            set { _valueFromPipelineByPropertyName = value; }
        }
        private bool _valueFromPipelineByPropertyName = false;

        [Parameter(ValueFromPipelineByPropertyName = true)]
        public bool ValueFromRemainingArguments
        {
            get { return _valueFromRemainingArguments; }
            set { _valueFromRemainingArguments = value; }
        }
        private bool _valueFromRemainingArguments = false;

        [Parameter(ValueFromPipelineByPropertyName = true)]
        public string HelpMessage
        {
            get { return _helpMessage; }
            set
            {
                if ((value != null) && (value.Length > 200))
                    throw new ArgumentOutOfRangeException("HelpMessage");

                _helpMessage = value;
            }
        }
        private string _helpMessage = null;

        [Parameter(ValueFromPipelineByPropertyName = true)]
        public string HelpMessageBaseName
        {
            get { return _helpMessageBaseName; }
            set
            {
                if ((value != null) && (value.Length > 200))
                    throw new ArgumentOutOfRangeException("HelpMessageBaseName");

                _helpMessageBaseName = value;
            }
        }
        private string _helpMessageBaseName = null;

        [Parameter(ValueFromPipelineByPropertyName = true)]
        public string HelpMessageResourceId
        {
            get { return _helpMessageResourceId; }
            set
            {
                if ((value != null) && (value.Length > 200))
                    throw new ArgumentOutOfRangeException("HelpMessageResourceId");

                _helpMessageResourceId = value;
            }
        }
        private string _helpMessageResourceId = null;

        protected override void ProcessRecord()
        {
            if (ShouldProcess(
                String.Format("{0}", ServiceUri),
                String.Format(resources.CreatePsSpecCmdletParameterSetEntryShouldrocess, ParameterName)))
            {
                try
                {
                    Service.NewParameterSetEntry(ProjectName, CmdletName, ParameterSetName, ParameterName,
                                                 Mandatory, Position, ValueFromPipeline, ValueFromPipelineByPropertyName,
                                                 ValueFromRemainingArguments, HelpMessage, HelpMessageBaseName,
                                                 HelpMessageResourceId);
                }
                catch (System.Web.Services.Protocols.SoapException e)
                {
                    WriteError(new ErrorRecord(e, "CMDLET_SERVICE_ERROR",
                                               ErrorCategory.InvalidOperation,
                                               String.Format(resources.CreatePsSpecCmdletParameterSetEntryShouldrocess,
                                                             ParameterName)));
                }
            }
            else
            {
            }
        }
    }
}
